from tkinter import *
from tkinter.ttk import *
class WinGUI(Tk):
    def __init__(self):
        super().__init__()
        self.__win()
        self.tk_tabs_page = self.__tk_tabs_page(self)
        self.tk_table_black_list = self.__tk_table_black_list( self.tk_tabs_page_0)
        self.tk_table_send_history = self.__tk_table_send_history( self.tk_tabs_page_1)
        self.tk_input_black_company = self.__tk_input_black_company( self.tk_tabs_page_0)
        self.tk_button_add_black = self.__tk_button_add_black( self.tk_tabs_page_0)
        self.tk_button_delete_black = self.__tk_button_delete_black( self.tk_tabs_page_0)
        self.tk_button_login = self.__tk_button_login(self)
        self.tk_label_send_url = self.__tk_label_send_url(self)
        self.tk_label_send_num = self.__tk_label_send_num(self)
        self.tk_input_send_url = self.__tk_input_send_url(self)
        self.tk_input_send_num = self.__tk_input_send_num(self)
        self.tk_button_start_send = self.__tk_button_start_send(self)
    def __win(self):
        self.title("boss_自动投递")
        # 设置窗口大小、居中
        width = 328
        height = 534
        screenwidth = self.winfo_screenwidth()
        screenheight = self.winfo_screenheight()
        geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
        self.geometry(geometry)
        
        self.resizable(width=False, height=False)
        
    def scrollbar_autohide(self,vbar, hbar, widget):
        """自动隐藏滚动条"""
        def show():
            if vbar: vbar.lift(widget)
            if hbar: hbar.lift(widget)
        def hide():
            if vbar: vbar.lower(widget)
            if hbar: hbar.lower(widget)
        hide()
        widget.bind("<Enter>", lambda e: show())
        if vbar: vbar.bind("<Enter>", lambda e: show())
        if vbar: vbar.bind("<Leave>", lambda e: hide())
        if hbar: hbar.bind("<Enter>", lambda e: show())
        if hbar: hbar.bind("<Leave>", lambda e: hide())
        widget.bind("<Leave>", lambda e: hide())
    
    def v_scrollbar(self,vbar, widget, x, y, w, h, pw, ph):
        widget.configure(yscrollcommand=vbar.set)
        vbar.config(command=widget.yview)
        vbar.place(relx=(w + x) / pw, rely=y / ph, relheight=h / ph, anchor='ne')
    def h_scrollbar(self,hbar, widget, x, y, w, h, pw, ph):
        widget.configure(xscrollcommand=hbar.set)
        hbar.config(command=widget.xview)
        hbar.place(relx=x / pw, rely=(y + h) / ph, relwidth=w / pw, anchor='sw')
    def create_bar(self,master, widget,is_vbar,is_hbar, x, y, w, h, pw, ph):
        vbar, hbar = None, None
        if is_vbar:
            vbar = Scrollbar(master)
            self.v_scrollbar(vbar, widget, x, y, w, h, pw, ph)
        if is_hbar:
            hbar = Scrollbar(master, orient="horizontal")
            self.h_scrollbar(hbar, widget, x, y, w, h, pw, ph)
        self.scrollbar_autohide(vbar, hbar, widget)
    def __tk_tabs_page(self,parent):
        frame = Notebook(parent)
        self.tk_tabs_page_0 = self.__tk_frame_page_0(frame)
        frame.add(self.tk_tabs_page_0, text="黑名单")
        self.tk_tabs_page_1 = self.__tk_frame_page_1(frame)
        frame.add(self.tk_tabs_page_1, text="投递记录")
        frame.place(x=0, y=188, width=323, height=346)
        return frame
    def __tk_frame_page_0(self,parent):
        frame = Frame(parent)
        frame.place(x=0, y=188, width=323, height=346)
        return frame
    def __tk_frame_page_1(self,parent):
        frame = Frame(parent)
        frame.place(x=0, y=188, width=323, height=346)
        return frame
    def __tk_table_black_list(self,parent):
        # 表头字段 表头宽度
        columns = {"ID":64,"企业名":257}
        tk_table = Treeview(parent, show="headings", columns=list(columns),)
        for text, width in columns.items():  # 批量设置列属性
            tk_table.heading(text, text=text, anchor='center')
            tk_table.column(text, anchor='center', width=width, stretch=False)  # stretch 不自动拉伸
        
        tk_table.place(x=0, y=36, width=323, height=284)
        return tk_table
    def __tk_table_send_history(self,parent):
        # 表头字段 表头宽度
        columns = {"ID":32,"投递时间":96,"岗位名":96,"企业名":96}
        tk_table = Treeview(parent, show="headings", columns=list(columns),)
        for text, width in columns.items():  # 批量设置列属性
            tk_table.heading(text, text=text, anchor='center')
            tk_table.column(text, anchor='center', width=width, stretch=False)  # stretch 不自动拉伸
        
        tk_table.place(x=0, y=0, width=323, height=319)
        return tk_table
    def __tk_input_black_company(self,parent):
        ipt = Entry(parent, )
        ipt.place(x=6, y=0, width=150, height=30)
        return ipt
    def __tk_button_add_black(self,parent):
        btn = Button(parent, text="加入", takefocus=False,)
        btn.place(x=170, y=0, width=50, height=30)
        return btn
    def __tk_button_delete_black(self,parent):
        btn = Button(parent, text="删除", takefocus=False,)
        btn.place(x=240, y=0, width=50, height=30)
        return btn
    def __tk_button_login(self,parent):
        btn = Button(parent, text="登录", takefocus=False,)
        btn.place(x=112, y=134, width=69, height=41)
        return btn
    def __tk_label_send_url(self,parent):
        label = Label(parent,text="投递url",anchor="center", )
        label.place(x=26, y=27, width=50, height=30)
        return label
    def __tk_label_send_num(self,parent):
        label = Label(parent,text="投递数量",anchor="center", )
        label.place(x=27, y=73, width=50, height=30)
        return label
    def __tk_input_send_url(self,parent):
        ipt = Entry(parent, )
        ipt.place(x=91, y=27, width=200, height=30)
        return ipt
    def __tk_input_send_num(self,parent):
        ipt = Entry(parent, )
        ipt.place(x=91, y=73, width=200, height=30)
        return ipt
    def __tk_button_start_send(self,parent):
        btn = Button(parent, text="开始投递", takefocus=False,)
        btn.place(x=209, y=134, width=69, height=41)
        return btn
class Win(WinGUI):
    def __init__(self, controller):
        self.ctl = controller
        super().__init__()
        self.__event_bind()
        self.__style_config()
        self.ctl.init(self)
    def __event_bind(self):
        self.tk_button_add_black.bind('<Button-1>',self.ctl.add_black)
        self.tk_button_delete_black.bind('<Button-1>',self.ctl.delete_black)
        self.tk_button_login.bind('<Button-1>',self.ctl.login)
        self.tk_button_start_send.bind('<Button-1>',self.ctl.start_send)
        self.tk_tabs_page.bind('<<NotebookTabChanged>>', self.ctl.on_tab_changed)
        pass
    def __style_config(self):
        pass
if __name__ == "__main__":
    win = WinGUI()
    win.mainloop()